<?php
//获取文件后缀
function separation($file_name)
{
$retval="";
$pt=strrpos($file_name,".");
if ($pt) $retval=substr($file_name,$pt+1,strlen($file_name)-$pt);
return ($retval);
}

function createFolders($path)   
{   
    if (!file_exists($path))
    {   
        createFolders(dirname($path));
        mkdir($path, 0777);   
    }   
}
?>
<?php
if($_POST[act]){
    $type=$_FILES['file_img']['name'];
	$name=date("Ymdhis",time()).rand(99,999).".".separation($type);
	$name2=date('Y-m-d')."/".$name;
	echo separation($type);
    createFolders("../../ziliao/down"."/".date("Y-m-d")); 
    if($type){
           $size=$_FILES["file_img"]["size"];
		   $updir = "../../ziliao/down/".date('Y-m-d')."/";//文件位置
		   $tmp_name=$_FILES["file_img"]["tmp_name"];
		   
           move_uploaded_file($tmp_name,$updir.$name);
		   echo "<script>opener.document.form1.picture.value='$name2';window.close();</script>";exit;
    }else{
	       echo "<script>alert('上传失败');location='javascript:history.go(-1)';</script>";exit;
     }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>上传附件</title>
</head>
<style type="text/css">
<!--
body {
	background-color: #DFF2FF;
}
-->
</style>
<body>
<?php
session_start();
if($_SESSION['admin_user']){
?>
<form name='form1' action='' method='post' enctype='multipart/form-data'> 
<table width="90%" border="0" cellspacing="1" cellpadding="0" align="center"> 
  <tr>
   <td align='center'><input type='file' name='file_img'>&nbsp;<input type='submit' name='Submit' value=' 上 传 ' class='input2'></td><input type="hidden" name="act" value="ok" />
   </tr>
   <tr>
     <td height="25" align="center">注：请不要上传图片</td>
   </tr>
</table>
</form>
<?php
}else{
?>
<div align="center"><a href="javascript:window.close();"><font color="#FF0000">非法操作</font></a></div>
<?php
}?>
</BODY>
</HTML>
